package com.rem.concurrency.multithreading.syn;

import lombok.SneakyThrows;

import java.util.concurrent.CopyOnWriteArrayList;

/**
 * GUC包下 线程安全的list
 * @author Rem
 * @date 2021-03-05
 */

public class SafeList {


    @SneakyThrows
    public static void main(String[] args){

        CopyOnWriteArrayList<String> strings = new CopyOnWriteArrayList<>();

        for (int i = 0; i < 10000; i++) {
            new Thread(() -> {
                strings.add(Thread.currentThread().getName());

            }).start();
        }

        Thread.sleep(100);

        System.err.println(strings.size());


    }
}
